<template>
  <div class="L">
    <div class="List">
      <van-nav-bar title="订单列表" left-text="返回" left-arrow @click-left="onClickLeft" fixed />
    </div>
    <div class="list-content" id="list-content">
      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list
          :immediate-check="false"
          :finished="finished"
          finished-text="没有更多了"
          v-model="loading"
          @load="onLoad"
          :offset="30"
        >
          <div class="item" v-for="(item,index) in list" :key="index" @click="detail(item)">
            <ul class="list">
              <li>订单编号:{{item.orderCode}}</li>
              <li>{{item.remark}}</li>
            </ul>
            <ul class="list">
              <li>订单名称:{{item.orderName}}</li>
              <li>箱子id:{{item.boxId}}</li>
            </ul>
            <ul class="list">
              <li>箱子编号:{{item.boxCode}}</li>
              <li>箱子规格:{{item.boxStandard}}</li>
            </ul>
            <ul class="list">
              <li>订单积分单价:{{item.boxUnitPrice}}</li>
              <li>租赁时长:{{item.leaseDuration}}小时</li>
            </ul>
            <ul class="list">
              <li
                v-show="(item.status ==1 ||item.status ==2||item.status ==3)"
              >行李箱下单时间:{{item.emptyBoxOrderTime}}</li>
              <li
                v-show="(item.status ==4 || item.status == 5||item.status ==6 ||item.status ==7||item.status ==8)"
              >行李箱提取时间:{{item.heavyBoxOrderTime}}</li>
            </ul>
          </div>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script>
import $ from "jquery";
export default {
  name: "entlist",
  mounted: function() {
    this.onLoad();
    let winHeight = document.documentElement.clientHeight;
    document.getElementById("list-content").style.height =
      winHeight - 46 + "px";
  },
  data() {
    return {
      finished: false,
      loading: false,
      emptyIsShow: false,
      heavyIsShow: true,
      list: [],
      pageNum: 1,
      pageSize: 4,
      refreshing: false,
      tem: "",
      total: 0
    };
  },

  methods: {
    onClickLeft() {
      this.$router.push("/home");
    },
    getData() {
      var list = {};
      $.ajax({
        url:
          "prod-api/app/order/list?" +
          "pageNum=" +
          this.pageNum +
          "&pageSize=" +
          this.pageSize,
        //url
        type: "get",
        async: false,
        //是否异步

        headers: {
          Authorization: " Bearer " + localStorage.getItem("token")
        },
        timeout: 5000, //超时时间

        dataType: "json", //规定预计的服务器响应的数据类型
        //请求前函数
        beforeSend: function(xhr) {},

        //请求成功函数
        success: function(data, textStatus, jqXHR) {
          if (200 == data.code) {
            list.data = data.rows;
            list.total = data.total;
          }
        },
        //请求失败函数
        error: function() {
          this.$toast.fail("获取失败");
        },

        //请求完成函数
        complete: function() {}
      });
      return list;
    },
    onLoad() {
      // 异步更新数据

      setTimeout(() => {
        if (this.refreshing) {
          this.list = [];
          //this.pageNum = this.pageNum + 1;
          this.refreshing = false;
        }
        this.tem = this.getData().data;
        this.total = this.getData().total;
        console.log(this.tem);
        console.log(this.total);
        for (let i = 0; i < this.tem.length; i++) {
          if (this.tem[i].status == 1) {
            this.tem[i].remark = "已经预约";
          } else if (this.tem[i].status == 2) {
            this.tem[i].remark = "正在存储";
          } else if (this.tem[i].status == 3) {
            this.tem[i].remark = "等待转运或提取";
          } else if (this.tem[i].status == 4) {
            this.tem[i].remark = "正在转运";
          } else if (this.tem[i].status == 5) {
            this.tem[i].remark = "行李到达";
          } else if (this.tem[i].status == 6) {
            this.tem[i].remark = "正在存储";
          } else if (this.tem[i].status == 7) {
            this.tem[i].remark = "订单完成";
          }
          this.list.push(this.tem[i]);
        }
        //console.log(this.list);

        // 加载状态结束
        this.loading = false;
        this.pageNum = this.pageNum + 1;
        // 数据全部加载完成
        if (this.list.length >= this.total) {
          this.finished = true;
        }
      }, 500);
    },
    onRefresh() {
      //下拉刷新

      this.finished = false;
      this.refreshing = true;
      //this.listData = [];

      this.loading = true;
      //this.getData();
      this.pageNum = 1;
      this.onLoad();
    },
    detail(item) {
      this.$router.push({
        name: "listDetail",
        params: { id: item.id }
      });
    }
  }
};
</script>

<style scoped>
.list-content {
  background-color: #eee;
  margin-top: 46px;
  overflow: scroll;
}
.list {
  width: 92%;
  display: flex;
  justify-content: space-between;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px solid #eee;
  margin: 0 auto;
  font-size: 14px;
  box-sizing: border-box;
}
.item {
  width: 100%;
  margin-top: 20px;
  background: #fff;
}
.list-item {
  text-align: center;
}
.van-nav-bar {
  background: url(../assets/bg2.png);
}
.list-content {
  margin-top: 46px;
  overflow: scroll;
}
</style>
